package de.fanuffel.mes.server;

import de.fanuffel.mes.model.World;

public class ModelServer {
  World world;
  boolean finish;
  Logger handler;

  public ModelServer(World world) {
    this.world = world;
    this.finish = false;
    this.handler = new Logger();
  }

  void report(String what) { handler.event(what); }

  void mainLoop() throws InterruptedException {
    report("startup");
    long startTime = System.currentTimeMillis();
    while (!finish) {
      Thread.sleep(100);
      long now = System.currentTimeMillis();
      finish = world.advance(now - startTime);
      startTime = now;
    }
    report("end");
  }

  public void run() throws InterruptedException {
    // TODO(karlklose): load model
    mainLoop();
    // TODO(karlklose): save mode
  }
}
